//
//  CZQCatergoryTableViewCell.m
//  LoveBeer
//
//  Created by 崔正强 on 17/5/7.
//  Copyright © 2017年 崔正强. All rights reserved.
//

#import "CZQCatergoryTableViewCell.h"
#import "LoveBeer.pch"

@interface CZQCatergoryTableViewCell()
//商品类别信息
@property (weak, nonatomic) IBOutlet UILabel *labTitle;
@property (weak, nonatomic) IBOutlet UIImageView *imgBig;
@property (weak, nonatomic) IBOutlet UIImageView *imgADFirst;
@property (weak, nonatomic) IBOutlet UIImageView *ImgADSecond;
@property (weak, nonatomic) IBOutlet UIImageView *imgADLast;
@property (weak, nonatomic) IBOutlet UILabel *labADDesFirst;
@property (weak, nonatomic) IBOutlet UILabel *labADDesSecond;
@property (weak, nonatomic) IBOutlet UILabel *labADDesLast;
@property (weak, nonatomic) IBOutlet UILabel *labADFirstPrice;
@property (weak, nonatomic) IBOutlet UILabel *labADFirstOldPrice;
@property (weak, nonatomic) IBOutlet UILabel *labADSecondPrice;
@property (weak, nonatomic) IBOutlet UILabel *labSecondOldPrice;
@property (weak, nonatomic) IBOutlet UILabel *labLastPrice;
@property (weak, nonatomic) IBOutlet UILabel *labLastOldPrice;
//跳转到超市
@property (weak,nonatomic)  UIControl* jumpControl;

@end

@implementation CZQCatergoryTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupUI];
    self.model = [CZQGoodsModel new];
}

- (void)setupUI{
    UIControl* jumpControl = [[UIControl alloc]init];
    self.jumpControl = jumpControl;
    [self.contentView addSubview:jumpControl];
    //    [jumpControl sizeToFit];
    
    [jumpControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.contentView).offset(-10);
        make.centerY.equalTo(self.labTitle.mas_bottom);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    
    
    UILabel* label = [[UILabel alloc]init];
    label.text = @"更多";
    label.textColor = [UIColor darkGrayColor];
    [label sizeToFit];
    [jumpControl addSubview:label];
    
    
    
    UIImageView* imgView = [[UIImageView alloc]init];
    imgView.image = [UIImage imageNamed:@"icon_go"];
    [jumpControl addSubview:imgView];
    
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.centerY.equalTo(jumpControl);
        make.width.mas_equalTo(5);
        make.height.mas_equalTo(10);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imgView);
        make.trailing.equalTo(imgView.mas_leading).offset(-7);
    }];
    
    //添加点击事件
    [jumpControl addTarget:self action:@selector(actionJumpToMarket:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - 点击事件 -
//跳转到闪电超市
- (void)actionJumpToMarket:(UIControl*)sender{
    if(self.CatergorySelectedBlock){
        self.CatergorySelectedBlock();
    }
}

- (IBAction)actionAddGoods:(UIButton *)sender {
    UIImageView* imgIcon;
    
    switch (sender.tag) {
        case 1:
            imgIcon = self.imgADFirst;
            break;
        case 2:
            imgIcon = self.ImgADSecond;
            break;
        case 3:
            imgIcon = self.imgADLast;
            
        default:
            break;
    }
    
    CGPoint imgIconCenter = imgIcon.center;
    
    CGPoint point = [ self convertPoint:imgIconCenter toView:kWindow];
    [[NSNotificationCenter defaultCenter]postNotificationName:CZQHomeIncreaseGoodNotification object:nil userInfo:@{                KIncreaseGoodPoint:[NSValue valueWithCGPoint:point],
                                                                                                                                    KIncreaseGoodImage:imgIcon.image,
                                                                                                                                    KIncreaseGoodsModel:self.model                                                           }] ;
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
